package com.wltjack.springboot.vo.common;

import com.wltjack.springboot.common.ResponseCode;

import java.util.List;

/**
 * 结果封装类
 */
public class ResultVO {

	/**
	 * 返回code
	 */
	private int code;

	/**
	 * 返回提示
	 */
	private String msg;

	/**
	 * 返回数据
	 */
	private Object data;

	public ResultVO(Object data){
		this(0,"成功",data);
	}
	
	public ResultVO(int code,String msg,Object data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	
	public ResultVO(int total,int pageSize,int pageNo,List<?> dataList) {
		int pageCnt = (int)Math.ceil((double)total/(double)pageSize);
		PageVO page = new PageVO();
		page.setTotal(total);
		page.setDataList(dataList);
		page.setPageCount(pageCnt);
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		this.code = ResponseCode.DATA_CODE_OK;
		this.msg = ResponseCode.DATA_SUCCESS;
		this.setData(page);
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}
